package com.no.pokerclub.core.spring;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ApplicationContextProviderSingleton implements
		ApplicationContextProvider {

	private static ApplicationContext context;
	
	public ApplicationContext createContext() {
		AbstractApplicationContext context = new ClassPathXmlApplicationContext(
				getContextLocations());
		context.registerShutdownHook();
		return context;
	}
	
	public ApplicationContext getContext() {
		if (context == null) context = createContext();
		return context;
	}

	public String[] getContextLocations() {
		String[] contextLocations = {
				"META-INF/com/no/pokerclub/core/spring/context.xml",
				"META-INF/com/no/pokerclub/core/hsqldb/context.xml",
				"META-INF/com/no/pokerclub/core/hibernate/context.xml",
				"META-INF/com/no/pokerclub/metamodel/context.xml",
				"META-INF/com/no/pokerclub/service/context.xml"
			};
		return contextLocations;
	}

}
